# https://leetcode.cn/problems/jump-game/description/

from collections import deque


class Solution:
    @staticmethod
    def canJump(nums: list[int]) -> bool:
        numsSize = len(nums)
        pt = deque([(0, nums[0])])
        visited = [False if _ != 0 else True for _ in range(numsSize)]
        while pt:
            index, val = pt.popleft()
            if index == numsSize - 1:
                return True
            for i in range(min(index + val, numsSize - 1), index, -1):
                if not visited[i]:
                    pt.append((i, nums[i]))
                    visited[i] = True
                else:
                    break
        return False
